//比亚迪中控
import QtQuick 2.15
import QtQuick.Window 2.15
import UIModule 1.0
import "./common" as Com
import "./ball" as BAL
//import QtQuick.VirtualKeyboard 2.15

Window {
    id: window
    width: Qt.platform.os === "windows"?720:Screen.width
    height: Qt.platform.os === "windows"?360:Screen.height  // 设置窗口大小为屏幕大小
    visible: true
   // visibility: Window.AutomaticVisibility
    property bool changFlag:false
    color: "transparent"
    title: qsTr("PM")
    flags: Qt.platform.os === "windows"?Qt.Window:(Qt.FramelessWindowHint|Qt.Window)
    //andriod 沉浸
    visibility: Qt.platform.os === "windows"?Window.AutomaticVisibility:Window.FullScreen
    //Screen.keepScreenOn: true
    Rectangle{
        anchors.fill:parent
        color:"#000000"
        Item{
            anchors.fill:parent
            UIView{
                id:uiView
                width: parent.width
                height: parent.height
                //长按菜单

            }
            Com.XMouseArea{
                id:xMA
                anchors.centerIn:parent
                width:parent.width*0.8
                height:parent.height*0.8
                onClicked:function(keyStr) {
                    uiView.y = 0

                    if(keyStr === "long"){
                        var parentPos = xMA.mapToItem(parent,  xMA.point.position.x, xMA.point.position.y)
                        let by =  parentPos.y-ballView.height/2
                        let bx = parentPos.x
                        ballView.leftBall= parent.width/2>bx?true:false
                        if(bx>parent.width/2) bx = bx-ballView.width+ballView.baseWith/2
                        else  bx-=ballView.baseWith/2

                        ballView.visible = false
                        ballView.x =bx
                        ballView.y =by
                        ballView.visible = true
                    }
                    else if(keyStr === "short"){
                        ballView.hided()
                    }
                    window.changFlag = false
                }
                 onSwipe:function( direction, value)  {//识别手势
                     if(direction === "up"){
                         uiView.y =-value
                     }
                     else if(direction === "left"){
                         uiView.moveX = -value
                     }
                     else if(direction == "right"){
                            uiView.moveX = value
                     }
                     else if(direction == "down"){
                        window.changFlag = true
                     }
                 }
            }
            BAL.BallView{
            id:ballView

            visible: false
        }
            visible:UI.light>20?true:false
        }
    }


}
